package com.hxx.day4;

public class TestDemo1 {
    public static void main(String[] args) {
        Person person1 = new Person();
        person1.setName("张三");
        person1.setAge(18);

        Person person2 = new Person();
        person2.setName("张三");
        person2.setAge(19);

        System.out.println(person1.equals(person2));
    }
}

class Person {
    private String name;
    private int age;

    //可以根据自己的条件判断是否相同
    @Override
    public boolean equals(Object obj) {
        //判断类型是否一致
        if (obj instanceof Person){
            Person person = (Person) obj;
            if (this == person){
                return true;
            }else{
                return this.name.equals(person.name) && this.age == person.age ;
            }
        }
        return false;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}




























